home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / demo / aga / rj-mblue.lha / rj-mblue512.asm < prev    next >
Assembly Source File  |  1998-09-06  |  7KB  |  304 lines

  1.  
  2. Code_Start:
  3.  
  4. Init:    
  5.  
  6. *First of all let me say that this code is very slow,
  7. *and so you have to see it on fast machine (ie. 040/060)
  8. *There is another problem related to cpu speed,
  9. *in fact i change camera parameters on vertical blank
  10. *this mean that if you haven't a fast machine you'll see tunnel
  11. *deform along frame calculation (from top to bottom of the screen)
  12. *So, slower machine equal to worse screen results.
  13. *Btw, on my a4000 (040/25) the 'trick' is almost non-noticeble.
  14.  
  15. *Coded by nAo/rAMjAM in August 1998
  16.     
  17.     Lea    Base,a0
  18.  
  19. *here lies a dumb palette generator :D
  20.  
  21.     move.l    a0,a1
  22.     moveq    #-1,d7            ;just 256 color :-)
  23.     moveq    #0,d0
  24. .pal    move.l    d0,(a1)+
  25.     add.l    #$00010102,d0        ;spread black to blue 
  26.     subq.b    #1,d7
  27.     bcc.s    .pal
  28.     bsr.w    SetPalette        ;loads palette
  29.  
  30.  
  31. steps    equ    2048            ;sin/cos table steps
  32. factor    equ    steps*10000/2/31415    ;fixed point factor
  33.  
  34.     move.l    a1,a2            ;saves sin table pointer
  35.     move.l    #factor,d5        ;this piece of code
  36.     move.w    #steps,d0        ;generates a sin/cos table
  37.     lsr.w    #3,d7            ;using an infinitesimal
  38.     mulu.w    d5,d0            ;rotation matrix 
  39.     moveq    #0,d2            ;u can find all the math stuff..
  40.                     ;on http://come.to/amiga
  41. .scloop    move.l    d2,d3            ;look at azure's doc with my final
  42.     divs.l    d5,d3            ;error correction chapter
  43.     move.w    d3,(a1)+        ;btw, this isn't the shortest
  44.     sub.l    d3,d0            ;way i know to generate a sin table
  45.     move.l    d0,d1            ;but afaik probably 
  46.     divs.l    d5,d1            ;it's the shortest way
  47.     move.w    d1,(a1)+        ;to make a sin/cos table
  48.     add.l    d1,d2
  49.     dbra    d7,.scloop
  50.  
  51.  
  52.  
  53. * This is V.R.T.G ************************************
  54. * Very Random Textures Generator :-D *****************
  55.  
  56.     
  57.     move.l    a1,a0            ;saves pointer
  58.     moveq    #4,d0
  59. .random    ror.l    d0,d0            ;tanx to Azure for this..
  60.     addq.l    #7,d0            ;smart (and chip) rnd generator
  61.     move.b    d0,(a0)+
  62. *    clr.b    (a0)+    
  63.     dbra    d7,.random
  64.  
  65.     moveq    #6-1,d4            ;filter passes
  66.     
  67. .start    moveq    #6-1,d6            ;blur passes
  68.     move.l    a1,a0
  69. .loopf    move.b    (a0),d0
  70.     lsl.b    #2,d0
  71.     bge.s    .ok
  72.     not.b    d0
  73. .ok    move.b    d0,(a0)+        ;this routine
  74.     dbra    d7,.loopf        ;perform a texture
  75. .loopbb    move.l    a1,a0            ;generator
  76.     move.l    a1,a5            ;using some rnd value
  77.     move.l    #256,d0            ;and some blur
  78.     move.l    d0,d1            ;and non-linear filters
  79.     neg.w    d1            
  80. .loopb    moveq    #0,d2            ;final resuslt it's
  81.     move.b    -1(a0),d2        ;completely emphyric
  82.     add.b    (a5,d0.l),d2        ;just work on
  83.     moveq    #0,d3            ;non-linear filter
  84.     move.b    1(a0),d3        ;and blur/filter passes to achieve
  85.     add.b    (a5,d1.l),d3        ;better results.
  86.     add.w    d2,d3
  87.     lsr.w    #2,d3            ;pay attention 
  88.     move.b    d3,(a0)+        ;to work on effective
  89.     addq.w    #1,d0            ;256x256 closed texture space
  90.     addq.w    #1,d1            ;to eliminate
  91.     dbra    d7,.loopb        ;tiling problems
  92.     dbra    d6,.loopbb
  93.     dbra    d4,.start
  94.  
  95.     move.l    a1,a5            *saves texture pointer
  96.     move.l    a0,a1            *saves grid pointer
  97.     lea    (33*33*8)(a1),a4    *saves temp pointer
  98.     move.l    a4,a0        
  99.     lea    (32*4)(a0),a0        *chunky pointer
  100.     rts                ;this rts can removed
  101.                     ;but who care? :)
  102.  
  103. VBlank:    ; Called every vblank after Init has finished.
  104.  
  105.     addq.w    #1,param4(a4)        ;here..
  106.     move.w    param4(a4),d0        ;just...
  107.     movem.w    (a2,d0.w*4),d0/d1    ;some...
  108.     asr.w    #1,d0            ;lissajeous..
  109.     asr.w    #2,d1            ;trick..
  110.     move.w    d0,param1(a4)        ;to move..
  111.     move.w    d1,param2(a4)        ;and rotate camera
  112.     move.w    (a2,d1.w*4,2048*2*4+384),d0
  113.     lsl.w    #3,d0
  114.     move.w    d0,param3(a4)
  115.     rts
  116.  
  117.  
  118. Main:    ; Called once when Init has finished.
  119.     ; Registers are as left by Init.
  120.     ; If it terminates, the demo will exit.
  121.  
  122.  
  123. * A5 --> Texture Pointer
  124. * A4 --> TempData Pointer
  125. * A2 --> Sin/Cos Pointer
  126. * A1 --> Grid Pointer
  127. * A0 --> Chunky Pointer
  128.  
  129.  
  130. param1        equ    0
  131. param2        equ    2
  132. param3        equ    4
  133. param4        equ    6    
  134.  
  135.  
  136.  
  137. Main2    bsr.b    Tracer            ;call ray tracer
  138.     bsr.w    Lattice            ;call lattice expander
  139.     bsr.w    Update256x256        
  140.     bra.b    Main2        
  141.  
  142.     rts
  143.  
  144. *very simple ray tracer
  145.  
  146. Tracer    movem.l    d0-a6,-(sp)
  147.     moveq    #32/2,d7
  148.     moveq    #-32/2,d1
  149. .y    moveq    #-32/2,d0
  150. .x    moveq    #26,d2        ;focal lenght
  151.  
  152.     move.w    param1(a4),d3    ;rotates ray on X axis
  153.     and.w    #$7ff,d3
  154.     movem.w    (a2,d3.w*4),d3/d4
  155.     move.l    d3,d5
  156.     move.l    d4,d6
  157.     muls.w    d2,d3        ;z*sin
  158.     muls.w    d1,d4        ;y*cos
  159.     muls.w    d1,d5        ;y*sin
  160.     muls.w    d2,d6        ;z*cos
  161.     add.l    d5,d6        ;Z
  162.     sub.l    d3,d4        ;Y
  163.  
  164.     move.l    d4,-(sp)
  165.  
  166.     move.w    param2(a4),d3    ;rotate ray on Y axis
  167.     and.w    #$7ff,d3
  168.     movem.w    (a2,d3.w*4),d3/d5
  169.     move.l    d3,d4
  170.     move.l    d5,d2
  171.     muls.w    d0,d3        ;x*sin
  172.     muls.l    d6,d4        ;z*sin
  173.     muls.w    d0,d2        ;x*cos
  174.     muls.l    d6,d5        ;z*cos
  175.     moveq    #11,d6
  176.     asr.l    d6,d4
  177.     asr.l    d6,d5
  178.     add.l    d2,d4        ;X
  179.     sub.l    d3,d5        ;Z
  180.     move.l    (sp)+,d6
  181.     move.l    d5,-(sp)
  182.  
  183.     move.l    d6,d5
  184.     move.l    d4,d6
  185.     asr.l    #6,d5
  186.     asr.l    #6,d4
  187.     muls.w    d5,d5
  188.     muls.w    d4,d4
  189.     add.l    d4,d5
  190.     addq.l    #1,d5
  191.  
  192.     moveq    #1,d3        ;thank goes to 
  193.     ror.l    #2,d3        ;Graham for this
  194.         moveq   #32,d2        ;fast and short sqrter
  195. .l2n
  196.         move.l  d3,d4
  197.         rol.l   d2,d4
  198.         add.w   d3,d3
  199.         cmp.l   d4,d5
  200.         bcs.b   .no
  201.         addq.w  #1,d3
  202.         sub.l   d4,d5
  203. .no
  204.         subq.w  #2,d2
  205.         bgt.b   .l2n
  206.  
  207. .ok    move.l    (sp)+,d4    ;i know that this isn't the academic
  208.     asl.l    #5,d4        ;way to make tunnels, but that's the
  209.     asl.l    #5,d6        ;only way i found that eliminates
  210.     divs.w    d3,d6        ;arctan calculation and short both
  211.     divs.w    d3,d4        ;(my atan routine is 100 bytes long....)
  212.     add.w    param3(a4),d4    ;Z axis camera traslation
  213.     move.w    d4,(a1)+    ;just write (u,v)
  214.     move.w    d6,(a1)+
  215.  
  216.     addq.l    #1,d0        ;next column
  217.     cmp.w    d7,d0
  218.     ble.w    .x
  219.     addq.l    #1,d1        ;next row
  220.     cmp.w    d7,d1
  221.     ble.w    .y
  222.     movem.l    (sp)+,d0-a6
  223.     rts
  224.  
  225.  
  226.  
  227. *A5-> texture pointer*
  228. *A1-> 33x33 (u,v) grid pointer*
  229. *A0-> chunky buffer*
  230.  
  231. ;I know that actually this routine it's slow
  232. ;but this is a short code compo, that isn't? :)
  233.  
  234. Lattice    movem.l    d0-a6,-(sp)
  235.     moveq    #32-1,d7        ;y loop counter
  236.     moveq    #10,d5
  237.     moveq    #0,d0
  238. .scanli    swap    d7
  239.     move.w    #32-1,d7        ;x loop counter
  240.     
  241. .square    move.l    a0,a6
  242.     move.l    (33*4)(a1),a4        ;(u4,v4)
  243.     move.l    (a1)+,d1        ;(u1,v1)
  244.     move.l    (33*4)(a1),a3        ;(u3,v3)
  245.     move.l    (a1),d2            ;(u2,v2)
  246.     sub.l    d1,a4            ;(u4-u1,v4-v1)
  247.     sub.l    d2,a3            ;(u3-u2,v3-v2)
  248.     lsl.l    #3,d1
  249.     lsl.l    #3,d2
  250.     moveq    #8-1,d6
  251.  
  252. .Yspan    move.l    d1,d3            ;(uL,vL)
  253.     move.l    d2,d4            ;(uR,vR)
  254.     swap    d6
  255.     sub.l    d3,d4            ;(uR-uL,vR-vL)
  256.     addq.w    #8,d6
  257.     asr.l    #3,d4
  258.     lsl.w    #3,d4
  259.     asr.w    #3,d4
  260.  
  261. .Xspan    move.w    d3,d0            ;need explanations
  262.     rol.l    #8,d3            ;this loop? :)
  263.     move.b    d3,d0            
  264.     ror.l    #8,d3
  265.     move.b    (a5,d0.l),(a6)+        ;just do it :-)
  266.     add.l    d4,d3            ;(u+du,v+dv)
  267.     subq.w    #1,d6
  268.     bne.s    .Xspan
  269.  
  270.     lea    256-8(a6),a6        ;next span
  271.     add.l    a4,d1            ;(uL+duL,vL+dvL)
  272.     add.l    a3,d2            ;(ur+duR,vR+dvR)
  273.     swap    d6            
  274.     dbra    d6,.Yspan
  275.  
  276.     addq.l    #8,a0            ;next nice little square
  277.     dbra    d7,.square
  278.     addq.l    #4,a1
  279.     lea    (256*7)(a0),a0
  280.     swap    d7
  281.     dbra    d7,.scanli
  282.     movem.l    (sp)+,d0-a6
  283.     rts
  284.     
  285.     
  286.  
  287.         printt    "Length of your code"
  288. Code_End:    printv    Code_End-Code_Start
  289.  
  290. ;; ******************** BSS area ********************
  291.  
  292.     section    BSS_Area,bss
  293.  
  294. ; declare BSS vars here. and only here
  295.  
  296.  
  297. Base        
  298. Palette        ds.l    256
  299. Sin        ds.l    2048*4
  300. Texture        ds.b    256*256
  301. Grid        ds.l    33*33*2
  302. TempData    ds.l    32
  303. Chunky        ds.b    256*256
  304. safe        ds.b    256*256